package com.yotoodesign.dianba.util;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.yotoodesign.dianba.bean.IMicroBlog;
import com.yotoodesign.dianba.bean.MicroBlogStatus;
import com.yotoodesign.dianba.bean.MicroBlogUser;

public class JSONUtil {
	/**
	 * 微博数据解析
	 * @param json
	 * @return
	 */
	public static List<IMicroBlog> parseMicroBlogStatus(String json) throws Exception{
		List<IMicroBlog> stautses = new ArrayList<IMicroBlog>();
		JSONObject jsonObject = new JSONObject(json);
		JSONArray jsonArray = jsonObject.getJSONArray("statuses");
		
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject statusJSON = jsonArray.getJSONObject(i);
			
			MicroBlogStatus status = new MicroBlogStatus(statusJSON);
			
			stautses.add(status);
		}
		
		return stautses;
	}
	
	public static String parseUID(String json){
		String uid = "";
		try{
			JSONObject jsonObject = new JSONObject(json);
			uid = jsonObject.getString("uid");
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return uid;
	}
	
	public static MicroBlogUser parseUser(String json){
		JSONObject userObject;
		MicroBlogUser usera = new MicroBlogUser();
		try {
			userObject = new JSONObject(json);
			usera = new MicroBlogUser(userObject);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.i(Constant.DIANBA,"ERROR>>>>>>>>>>>>>>"+e.getMessage());
		}
		return usera;
	}
}
